package org.gis.mapserver.suppliers.sources.sample;

import java.net.URL;
import org.gis.mapserver.base.ConfigBean;
import org.gis.mapserver.source.Source;
import org.gis.mapserver.source.SourceBuilder;
import org.gis.utils.beanloader.ConfigBeanLoader;
import org.gis.dbtools.UniqueID;

/**
 *
 * @author gus
 */
public class SampleSourceBuilder implements SourceBuilder
{
    private final static String URL_PROPERTY = "URL";
    
    private String resourceID;
    private ConfigBeanLoader configBeanLoader;

    public void setConfigBeanLoader( ConfigBeanLoader configBeanLoader )
    {
        this.configBeanLoader = configBeanLoader;
    }

    public void setResourceID( String resourceID )
    {
        this.resourceID = resourceID;
    }

    public Source makeSource() throws Exception
    {
        ConfigBean  configBean = configBeanLoader.loadConfigBean(new UniqueID(resourceID));
        String str = configBean.<String>getValue(URL_PROPERTY);
        URL  url = new URL(str);
        return new SampleSource(url.openStream());
    }
}
